﻿@{
    ViewBag.Title = "分组列表";
}
<link href="~/assets/js/bootstrap-table/bootstrap-table.min.css" rel="stylesheet" />


<div class="page-body">
    <div id="serch-form" class="form-inline">
        <a href="@Url.Action("Edit","Group")" class="btn btn-primary">创建分组</a>
        <div class="pull-right">
            <div class="input-group">
                <input type="text" class="form-control" placeholder="分组名" id="name">
                <span class="input-group-btn">
                    <button class="btn btn-default" type="button" id="btn_table_search" onclick="handlers.gridReload()"><i class="fa fa-search blue"></i></button>
                </span>
            </div>
        </div>
    </div>
    <table id="table" class="mychar1-table"></table>
</div>


@section scripts {
    <!--Page Related Scripts-->

    <script src="~/assets/js/bootstrap-table/bootstrap-table.min.js"></script>
    <script src="~/assets/js/bootstrap-table/bootstrap-table-zh-CN.min.js"></script>
    <script>
        hos.ui.util.breadCrumb("账号管理");
        var grid = hos.ui.ctrl.gridView("table", {
            url: '/Group/LoadScheduleGroupPager',
            columns: [{
                field: 'GroupName',
                title: '分组名称'
            }, {
                field: 'CreateUserName',
                title: '创建人'
            }, {
                field: 'CreateTime',
                title: '创建时间'
            },  {
                title: '操作',
                field: 'id',
                align: 'center',
                formatter: function (value, row, index) {
                    var l = '<a href="/Group/Edit?id=' + row.Id + '" class="btn btn-xs">编辑</a>  ';
                    l += '<button class="btn btn-xs btn-danger" onclick="handlers.groupDelete(\'' + row.Id + '\',\'' + row.GroupName + '\')">删除</button>';
                    return l;
                }
            }
            ]
        });
        var handlers = {
          
            groupDelete: function (value, title) {
                this.request(title, '/Group/Delete?id=' + value, "删除");
            },
            request: function (title, url, action) {
                hos.ui.util.confirm('确定要 <span style="color:red" > ' + action + '</span>【' + title + '】？',
                    function () {
                        hos.ui.util.postJson(url, null, function () { grid.reload(); })
                    });
            },
            gridReload: function () {
                var name = $("#name").val();
                var filter = JSON.stringify({ name});
                localStorage.setItem(window.location.pathname, filter);
                grid.reload();
            }

        }

        $(function () { 
            var filterString = localStorage.getItem(window.location.pathname)
            var filter = JSON.parse(filterString);
            if(filter){
                $("#name").val(filter.name);
                grid.reload();
            }
        })
    </script>
}

